package vip.zhenzicheng.concurrent_program.thread.sgg.interrupt;

import java.util.concurrent.TimeUnit;

/**
 * @author zhenzicheng
 * @date 2022-06-27 19:26
 */
public class InterruptDemo2 {

  public static void main(String[] args) {
    Thread t1 = new Thread(() -> {
      for (int i = 0; i < 300; i++) {
        System.out.println("----:" + i);
      }
    }, "t1");
    t1.start();

    System.out.println("t1线程默认中断标识：" + Thread.currentThread().isInterrupted());
    try {
      TimeUnit.MILLISECONDS.sleep(2);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    t1.interrupt(); // true
    System.out.println("t1线程调用 interrupt()后的中断标识：" + t1.isInterrupted());

    try {
      TimeUnit.SECONDS.sleep(2);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    System.out.println("t1线程调用 interrupt()后的中断标识：" + t1.isInterrupted());
  }
}
